<template>
	<view class="u-page">
		<view class="u-demo-block">
			<u-form
				:labelWidth="80"
				:model="formData"
				:rules="formRules"
				ref="form">
				<!-- 输入设备号 -->
				<u-form-item
					label="设备号"
					required
					prop="machineNo"
					ref="machineNo">
					<u-input
						v-model="formData.machineNo"
						disabled
					></u-input>
				</u-form-item>
				<!--lotNo -->
				<u-form-item
					label="lotNo"
					required
					prop="lotNo"
					ref="lotNo">
					<u-input
						v-model="formData.lotNo"
						clearable
						required
						disabled>
					</u-input>
				</u-form-item>
				<!-- 形名 -->
				<u-form-item
					label="形名"
					required
					prop="lotProductCode"
					ref="lotProductCode">
					<u-input
						v-model="formData.lotProductCode"
						clearable
						required
						:focus="focus.lotProductCode"
						@focus="lotProductCodeFocus"
						@blur="lotProductCodeBlur">
					</u-input>
				</u-form-item>
				<u-row gutter="10">
					<u-col span="3" >
						<u-text
							text="形名: "
						></u-text>
					</u-col>
					<u-col span="9">
						<u-text
							type="success"
							:text="echo.productCode"
							class="preWhite"
						></u-text>
					</u-col>
				</u-row>
				<!-- 选择时间 -->
				<u-form-item
					label="日期"
					required
					prop="recordTimeDT"
					ref="recordTimeDT"
					@click="recordTimeFormClick">
					<u-input
						v-model="formData.recordTimeDT"
						style="pointer-events: none"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择记录时间"
						fontSize="13px"
						color="#12569F">
					</u-input>
				</u-form-item>
				<!-- 组立机台 -->
				<u-form-item
					label="组立机台"
					required
					prop="zlMachineNo"
					ref="zlMachineNo"
					@click="zlPickerFormClick">
					<u-input
						v-model="formData.zlMachineNo"
						style="pointer-events: none"
						disabled
						disabledColor="#ffffff"
						placeholder="请选择组立设备"
						fontSize="13px"
						color="#12569F">
					</u-input>
				</u-form-item>
				<u-divider
					text="1列"
					lineColor="#12569F">					
				</u-divider>
				<u-form-item
					label="1列良品数"
					prop="okCount1"
					ref="okCount1"
					@click=" ((formData.okCount1*1)<1)?formData.okCount1='':formData.okCount1">
					<u-input
						v-model="formData.okCount1"
						type="number"
						@blur="((formData.okCount1*1)<1)?(formData.okCount1=0):''"
						@change="okCountChange"
						clearable>
					</u-input>
				</u-form-item>
				<u-form-item
					label="1列不良数"
					prop="ngCount1"
					ref="ngCount1"
					@click="((formData.ngCount1*1)<1)?(formData.ngCount1=''):formData.ngCount1">
					<u-input
						v-model="formData.ngCount1"
						type="number"
						@blur="((formData.ngCount1*1)<1)?(formData.ngCount1=0):''"
						clearable>
					</u-input>
				</u-form-item>
				
				<u-row gutter="10" class="ngEcho">
					<u-col span="3" >
						<u-text
							text="1列不良率: "
						></u-text>
					</u-col>
					<u-col span="9">
						<text style="color:#f56c6c;font-size:15px">{{ngPercent1}}</text>
					</u-col>
				</u-row>
				<u-form-item
					label="1列机械不良"
					labelWidth=100
					prop="jxngCount1"
					ref="jxngCount1"
					@click="((formData.jxngCount1*1)<1)?(formData.jxngCount1=''):formData.jxngCount1">
					<u-input
						v-model="formData.jxngCount1"
						type="number"
						@blur="((formData.jxngCount1*1)<1)?(formData.jxngCount1=0):''"
						clearable>
					</u-input>
				</u-form-item>
				<u-divider
					text="2列"
					lineColor="#12569F">					
				</u-divider>
				<u-form-item
					label="2列良品数"
					prop="okCount2"
					ref="okCount2"
					@click="((formData.okCount2*1)<1)?(formData.okCount2=''):formData.okCount2">
					<u-input
						v-model="formData.okCount2"
						type="number"
						@blur="((formData.okCount2*1)<1)?(formData.okCount2=0):''"
						@change="okCountChange"
						clearable>
					</u-input>
				</u-form-item>
				<u-form-item
					label="2列不良数"
					prop="ngCount2"
					ref="ngCount2"
					@click="((formData.ngCount2*1)<1)?(formData.ngCount2=''):formData.ngCount2">
					<u-input
						v-model="formData.ngCount2"
						type="number"
						@blur="((formData.ngCount2*1)<1)?(formData.ngCount2=0):''"
						clearable>
					</u-input>
				</u-form-item>
				
				<u-row gutter="10" class="ngEcho" >
					<u-col span="3" >
						<u-text
							text="2列不良率: "
						></u-text>
					</u-col>
					<u-col span="9">
						<text style="color:#f56c6c;font-size:15px">{{ngPercent2}}</text>
					</u-col>
				</u-row>
				<u-form-item
					label="2列机械不良"
					labelWidth=100
					prop="jxngCount2"
					ref="jxngCount2"
					@click="((formData.jxngCount2*1)<1)?(formData.jxngCount2=''):formData.jxngCount2">
					<u-input
						v-model="formData.jxngCount2"
						type="number"
						@blur="((formData.jxngCount2*1)<1)?(formData.jxngCount2=0):''"
						clearable>
					</u-input>
				</u-form-item>
				
				<u-divider
					text="3列"
					lineColor="#12569F">					
				</u-divider>
				<u-form-item
					label="3列良品数"
					prop="okCount3"
					ref="okCount3"
					@click=" ((formData.okCount1*3)<1)?formData.okCount3='':formData.okCount3">
					<u-input
						v-model="formData.okCount3"
						type="number"
						@blur="((formData.okCount3*1)<1)?(formData.okCount3=0):''"
						@change="okCountChange"
						clearable>
					</u-input>
				</u-form-item>
				<u-form-item
					label="3列不良数"
					prop="ngCount3"
					ref="ngCount3"
					@click="((formData.ngCount3*1)<1)?(formData.ngCount3=''):formData.ngCount3">
					<u-input
						v-model="formData.ngCount3"
						type="number"
						@blur="((formData.ngCount3*1)<1)?(formData.ngCount3=0):''"
						clearable>
					</u-input>
				</u-form-item>
				
				<u-row gutter="10" class="ngEcho" >
					<u-col span="3" >
						<u-text
							text="3列不良率: "
						></u-text>
					</u-col>
					<u-col span="9">
						<text style="color:#f56c6c;font-size:15px">{{ngPercent3}}</text>
					</u-col>
				</u-row>
				<u-form-item
					label="3列机械不良"
					labelWidth=100
					prop="jxngCount3"
					ref="jxngCount3"
					@click="((formData.jxngCount3*1)<1)?(formData.jxngCount3=''):formData.jxngCount3">
					<u-input
						v-model="formData.jxngCount3"
						type="number"
						@blur="((formData.jxngCount3*1)<1)?(formData.jxngCount3=0):''"
						clearable>
					</u-input>
				</u-form-item>
				
				<u-divider
					text="4列"
					lineColor="#12569F">					
				</u-divider>
				<u-form-item
					label="4列良品数"
					prop="okCount4"
					ref="okCount4"
					@click="((formData.okCount4*1)<1)?(formData.okCount4=''):formData.okCount4">
					<u-input
						v-model="formData.okCount4"
						type="number"
						@blur="((formData.okCount4*1)<1)?(formData.okCount4=0):''"
						@change="okCountChange"
						clearable>
					</u-input>
				</u-form-item>
				<u-form-item
					label="4列不良数"
					prop="ngCount4"
					ref="ngCount4"
					@click="((formData.ngCount4*1)<1)?(formData.ngCount4=''):formData.ngCount4">
					<u-input
						v-model="formData.ngCount4"
						type="number"
						@blur="((formData.ngCount4*1)<1)?(formData.ngCount4=0):''"
						clearable>
					</u-input>
				</u-form-item>
				
				<u-row gutter="10" class="ngEcho">
					<u-col span="3" >
						<u-text
							text="4列不良率: "
						></u-text>
					</u-col>
					<u-col span="9">
						<text style="color:#f56c6c;font-size:15px">{{ngPercent4}}</text>
					</u-col>
				</u-row>
				<u-form-item
					label="4列机械不良"
					labelWidth=100					
					prop="jxngCount4"
					ref="jxngCount4"
					@click="((formData.jxngCount4*1)<1)?(formData.jxngCount4=''):formData.jxngCount4">
					<u-input
						v-model="formData.jxngCount4"
						type="number"
						@blur="((formData.jxngCount4*1)<1)?(formData.jxngCount4=0):''"
						clearable>
					</u-input>
				</u-form-item>
				<u-divider
					text="合计"
					lineColor="#12569F">					
				</u-divider>
				<u-row gutter="10" class="ngEcho">
					<u-col span="4" >
						<u-text
							text="合计良品: "
						></u-text>
					</u-col>
					<u-col span="8">
						<text style="color:#007b43;font-size:15px">{{okSum}}</text>
					</u-col>
				</u-row>
				<u-row gutter="10" class="ngEcho" >
					<u-col span="4" >
						<u-text
							text="合计不良率: "
						></u-text>
					</u-col>
					<u-col span="8">
						<text style="color:#f56c6c;font-size:15px">{{ngSumPercent}}</text>
					</u-col>
				</u-row>
				<u-divider
						text="确认"
						lineColor="#12569F">					
					</u-divider>
					<u-form-item
						label="研磨材更换盖章确认"
						prop="ymcCheck"
						labelWidth=150>
						<u-input
							v-model="formData.ymcCheck"
							clearable
							@blur="ymcCheckBlur">
						</u-input>
					</u-form-item>
					<u-row gutter="10" class="ngEcho">
						<u-col span="4" >
							<u-text
								text="研磨材确认者:" 
							></u-text>
						</u-col>
						<u-col span="8">
							<u-text
								type="success"
								:text="echo.ymcCheckUserFullName">
							</u-text>
						</u-col>
					</u-row>
					<u-form-item
						label="lot结束"
						prop="lotEnd">
						<u-switch
							v-model="formData.lotEndFlag">
							
						</u-switch>
					</u-form-item>
				</u-form>
				
			</u-form>
			<u-button
				type="primary"
				text="提交"
				customStyle="margin-top: 20px"
				:loading="submitBtn.loading"
				loadingMode="semicircle"
				@click="formSubmit">
			</u-button>
			<u-button
				type="error"
				text="删除"
				customStyle="margin-top: 20px"
				@click="formDel">
			</u-button>
			
			<u-picker 
				:show="show.zlPicker" 
				:columns="zlMachineNoList"
				:closeOnClickOverlay="true"
				keyName="machineNo"
				@confirm="zlMachineConfirm"
				@close="show.zlPicker=false"
				@cancel="show.zlPicker=false">
			</u-picker>
			
			<u-calendar 
				:show="show.calendar"
				:defaultDate="defaultDate"
				:minDate="minDate"
				:maxDate="maxDate"
				:closeOnClickOverlay="true"
				mode="single"
				@confirm="calendarConfirm"
				@close="calendarClose">
			</u-calendar>
		</view>
	</view>
</template>

<script>
import { getMachine4SSD1BT,getUSMZuLiMachineList } from '@/api/machine/machine.js';
import { getUSMQrType } from '@/api/qrtype/qrtype.js';
import { getUsmBtRecordUnfinished,getUsmBtRecordByID,uptUsmBtRecord,delUsmBtRecord } from '@/api/usmRecord/usmBtRecord.js';
import { getUserCodeEcho4UDBSU } from '@/api/user/user.js' 
import  dayjs from "dayjs"
export default {
	data() {
		return {
			prePageOption:{},
			formData: {
				lotNo:'',
				lotProductCode:'',
				lotInfo: '',
				machineNo: '',
				recordTimeDT:'',
				zlMachineNo:'',
				okCount1:0,
				ngCount1:0,
				jxngCount1:0,
				okCount2:0,
				ngCount2:0,
				jxngCount2:0,
				okCount3:0,
				ngCount3:0,
				jxngCount3:0,
				okCount4:0,
				ngCount4:0,
				jxngCount4:0,
				ymcCheck:''		,//研磨材确认员工号
				lotEndFlag:false
			},
			formRules: {
				machineNo: [
					{
						type: 'string',
						required: true,
						message: '请输入设备号',
						trigger: ['blur', 'change']
					}
				],
				'lotNo': [
					{
						type:'string',
						len:12,
						required: true,
						message: '长度错误',
						trigger: ['blur']
					}
				],
				'lotInfo': {
					type: 'string',
					required: true,
					message: '请扫描二维码',
					trigger: ['blur', 'change']
				},
				'recordTimeDT':{
					type: 'string',
					required: true,
					message: '请选择日期',
					trigger: ['blur', 'change']
				},
				'zlMachineNo':{
					type: 'string',
					required: true,
					message: '请选择',
					trigger: ['blur', 'change']
				},
				'okCount1':{
					type:'number',
					required:false,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'ngCount1':{
					type:'number',
					required:false,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'jxngCount1':{
					type:'number',
					required:false,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'okCount2':{
					type:'number',
					required:false,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'ngCount2':{
					type:'number',
					require:true,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'jxngCount2':{
					type:'number',
					required:false,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'okCount3':{
					type:'number',
					required:false,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'ngCount3':{
					type:'number',
					required:false,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'jxngCount3':{
					type:'number',
					required:false,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'okCount4':{
					type:'number',
					required:false,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'ngCount4':{
					type:'number',
					require:true,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				'jxngCount4':{
					type:'number',
					required:false,
					message:'必须是数字',
					trigger: ['blur', 'change']
				},
				
			},
			focus: {
				machineNo: false,
				lotInfo: false,
				lotNo:false,
				lotProductCode:false,
			},
			echo: {
				lotNo: '',
				productCode: '',
				ymcCheckUserFullName:''
			},
			disabled: {
				machineNo: false
			},
			show: {
				otherItem: false,
				lotInfo:false,
				calendar:false,
				zlPicker:false
			},
			timer: {			
				lotNo: 0,
				lotProductCode:0,
				lotInfo: 0,
				machineNo: 0
			},
			qrCode:{
				lotNoFrom:0,
				lotNoLength:0,
				pnFrom:0,
				pnLength:0
			},
			defaultDate: '',
			minDate:dayjs().subtract(1,'month').format('YYYY-MM-DD'),
			maxDate:dayjs().add(1,'day').format('YYYY-MM-DD'),
			zlMachineNoList:[[]],
			submitBtn:{
				loading:false
			},
		};
	},
	onLoad(option) {
		this.prePageOption=option
		const that = this
		getUsmBtRecordByID(this.prePageOption)
		.then(res=>{
			this.formData.machineNo=res.data.machineNo
			this.formData.lotNo=res.data.lotNo
			this.echo.productCode=res.data.productCode
			this.formData.recordTimeDT = res.data.recordTimeDT
			this.formData.zlMachineNo = res.data.zlMachineNo
			this.formData.okCount1=res.data.okCount1
			this.formData.ngCount1=res.data.ngCount1
			this.formData.jxngCount1 = res.data.jxngCount1
			this.formData.okCount2=res.data.okCount2
			this.formData.ngCount2=res.data.ngCount2
			this.formData.jxngCount2 = res.data.jxngCount2
			this.formData.okCount3=res.data.okCount3
			this.formData.ngCount3=res.data.ngCount3
			this.formData.jxngCount3=res.data.jxngCount3
			this.formData.okCount4=res.data.okCount4
			this.formData.ngCount4=res.data.ngCount4
			this.formData.jxngCount4=res.data.jxngCount4
			this.formData.ymcCheck=res.data.ymcCheck
			uni.$u.sleep(200).then(()=>{
				that.formData.lotEndFlag=res.data.lotEndFlag
			})
			if(!uni.$u.test.isEmpty(this.formData.ymcCheck)) {
				getUserCodeEcho4UDBSU({userCode:this.formData.ymcCheck})
					.then(res=>{
						this.echo.ymcCheckUserFullName=res.data.usersPO.userFullName
					})
					.catch(err=>{
						uni.showToast({
							title: '未找到此员工',
							icon: 'error'
						});
						this.formData.ymcCheck=''
					})
			}
		})
		.catch(err=>{
			uni.showToast({
				title: err.msg||err.message,
				icon: 'error',
				duration: 2000,
			})
			uni.$u.sleep(2000).then(()=>{
				uni.navigateBack()
			})
		})
	},
	onShow() {

	},
	onUnload() {
		//清除计数器
		clearTimeout(this.timer.lotInfo);
		clearTimeout(this.timer.machineNo);
	},
	onNavigationBarButtonTap(e) {
		if (e.type === 'menu') {
			this.showMenuDrawer();
		} else if (e.type === 'home') {
			uni.reLaunch({
				url: '/pages/index/index'
			});
		}
	},
	computed:{
		ngPercent1(){
			if(!uni.$u.test.number(this.formData.okCount1)) return '0%'
			if(!uni.$u.test.number(this.formData.ngCount1)) return '0%'
			if((this.formData.okCount1+this.formData.ngCount1)<1) return '0%'

			return ((this.formData.ngCount1*1/(this.formData.okCount1*1+this.formData.ngCount1*1))*100).toFixed(3) + '%'
		},
		ngPercent2(){
			if(!uni.$u.test.number(this.formData.okCount2)) return '0%'
			if(!uni.$u.test.number(this.formData.ngCount2)) return '0%'
			if((this.formData.okCount2+this.formData.ngCount2)<1) return '0%'
		
			return ((this.formData.ngCount2*1/(this.formData.okCount2*1+this.formData.ngCount2*1))*100).toFixed(3) + '%'
		},
		ngPercent3(){
			if(!uni.$u.test.number(this.formData.okCount3)) return '0%'
			if(!uni.$u.test.number(this.formData.ngCount3)) return '0%'
			if((this.formData.okCount3+this.formData.ngCount3)<1) return '0%'
		
			return ((this.formData.ngCount3*1/(this.formData.okCount3*1+this.formData.ngCount3*1))*100).toFixed(3) + '%'
		},
		ngPercent4(){
			if(!uni.$u.test.number(this.formData.okCount4)) return '0%'
			if(!uni.$u.test.number(this.formData.ngCount4)) return '0%'
			if((this.formData.okCount4+this.formData.ngCount4)<1) return '0%'
		
			return ((this.formData.ngCount4*1/(this.formData.okCount4*1+this.formData.ngCount4*1))*100).toFixed(3) + '%'
		},
		okSum(){
			return (this.formData.okCount1*1+this.formData.okCount2*1+this.formData.okCount3*1+this.formData.okCount4*1)
		},
		ngSumPercent(){
			if((this.formData.okCount1*1+this.formData.ngCount1*1+this.formData.okCount2*1+this.formData.ngCount2*1+this.formData.okCount3*1+this.formData.ngCount3*1+this.formData.okCount4*1+this.formData.ngCount4*1)<1) return  '0%'
			return ((this.formData.ngCount1*1+this.formData.ngCount2*1+this.formData.ngCount3*1+this.formData.ngCount4*1)/(this.formData.okCount1*1+this.formData.ngCount1*1+this.formData.okCount2*1+this.formData.ngCount2*1+this.formData.okCount3*1+this.formData.ngCount3*1+this.formData.okCount4*1+this.formData.ngCount4*1)*100).toFixed(3) +'%'
		}
		
	},

	methods: {

		lotProductCodeFocus(){
			uni.$u.sleep(100).then(() => {
				// #ifdef APP-PLUS
				uni.hideKeyboard();
				// #endif				
			})
		},
		lotProductCodeBlur(){
				uni.$u.sleep(666).then(() => {
					if(this.formData.lotProductCode.length<1) return
					getUSMQrType()
						.then((res) => {
							this.qrCode.lotNoFrom=res.data.lotNoFrom
							this.qrCode.lotNoLength =res.data.lotNoLength
							this.qrCode.pnFrom = res.data.pnFrom
							this.qrCode.pnLength = res.data.pnLength
							this.show.lotInfo=true
							this.echo.productCode=this.formData.lotProductCode.substr(this.qrCode.pnFrom,this.qrCode.pnLength)
							this.formData.lotProductCode=''
						})
						.catch((err) => {
							uni.showToast({
								title: err.msg || err.message || '服务器异常',
								icon: 'error'
							});
						});
				})
		},
		
		
		recordTimeFormClick(){
			if(dayjs().hour()<7){
				this.defaultDate=dayjs().subtract(1,'day').format('YYYY-MM-DD')
			} 
			this.$nextTick(()=>{
				this.show.calendar=true
			})
		},
		calendarConfirm(e){
			if((!uni.$u.test.isEmpty(e))&&(uni.$u.test.array(e))){
				this.formData.recordTimeDT=e[0]
			}
			this.show.calendar=false
		},
		calendarClose(){
			this.show.calendar=false
		},
		zlPickerFormClick(){
			const _this=this
			getUSMZuLiMachineList()
				.then(res=>{
					this.zlMachineNoList=[res.data]
					this.$nextTick(()=>{
						_this.show.zlPicker=true
					})
				})
				.catch(err=>{
					uni.showToast({
						title: err.msg || err.message || '服务器异常',
						icon: 'error'
					});
				})
				
			
		},
		zlMachineConfirm(selected){
			if(!uni.$u.test.array(selected.value)) return
			this.formData.zlMachineNo=selected.value[0].machineNo
			this.show.zlPicker=false
		},
		ymcCheckBlur(){
			uni.$u.sleep(500).then(()=>{
				if(uni.$u.test.isEmpty(this.formData.ymcCheck)) return 
				getUserCodeEcho4UDBSU({userCode:this.formData.ymcCheck})
					.then(res=>{
						this.echo.ymcCheckUserFullName=res.data.usersPO.userFullName
					})
					.catch(err=>{
						uni.showToast({
							title: '未找到此员工',
							icon: 'error'
						});
						this.formData.ymcCheck=''
					})
			})
		},
		okCountChange(e){			
			if((this.formData.okCount1+this.formData.ngCount1)>0 && (this.formData.okCount2+this.formData.ngCount2)>0 && (this.formData.okCount3+this.formData.ngCount3)>0 && (this.formData.okCount4+this.formData.ngCount4)>0) {
				this.formData.lotEndFlag=true
			} else {
				this.formData.lotEndFlag =false
			}
			
		},
		formSubmit(){
			const _this=this;
			if((!uni.$u.test.isEmpty(this.formData.ymcCheck))&&(uni.$u.test.isEmpty(this.echo.ymcCheckUserFullName))){
				uni.showToast({
					title: '研磨材验证失败',
					icon: 'error'
				});
				return 
			}
			// 数据验证
			this.$refs.form.validate()
				.then(res=>{		//成功时返回true
					uni.showModal({
						title:'上传',
						content:'确认数据上传?',
						success:(res)=>{
							if(res.confirm){
								const uploadData={
									recordID: _this.prePageOption.recordID,
									machineNo: _this.formData.machineNo,
									lotNo:_this.formData.lotNo,
									productCode:_this.echo.productCode,
									recordTimeDT:_this.formData.recordTimeDT,
									zlMachineNo:_this.formData.zlMachineNo,
									okCount1:_this.formData.okCount1,
									ngCount1:_this.formData.ngCount1,
									jxngCount1:_this.formData.jxngCount1,
									okCount2:_this.formData.okCount2,
									ngCount2:_this.formData.ngCount2,
									jxngCount2:_this.formData.jxngCount2,
									okCount3:_this.formData.okCount3,
									ngCount3:_this.formData.ngCount3,
									jxngCount3:_this.formData.jxngCount3,
									okCount4:_this.formData.okCount4,
									ngCount4:_this.formData.ngCount4,
									jxngCount4:_this.formData.jxngCount4,
									ymcCheck:_this.formData.ymcCheck,
									lotEndFlag:_this.formData.lotEndFlag
								};
								this.submitBtn.loading=true
								uptUsmBtRecord(uploadData)
									.then(res=>{
										uni.showToast({
											title:'提交成功',
											duration:2000
										})
										uni.$u.sleep(2000).then(()=>{
											this.submitBtn.loading=false
											uni.navigateBack()											
										})
									})
									.catch(err=>{
										uni.showToast({
											title: err.msg||' 服务器异常',
											icon:'error',
											duration:2000
										})
										uni.$u.sleep(2000).then(()=>{
											this.submitBtn.loading=false
										})
									})
								
							}
						}
						
					})
				})
				.catch(err=>{
					uni.showToast({
						title:'提交数据错误',
						icon:'error',
						duration:2000
					})
				})
			
		},
		formDel(){
			const _this=this
			uni.showModal({
				title:'删除',
				content:'确认删除数据??',
				success:(res)=>{
					if(res.confirm){
						const delData = {
							recordID:_this.prePageOption.recordID
						}
						delUsmBtRecord(delData)
							.then(res=>{
								uni.showToast({
									title:'删除成功',
									duration:2000
								})
								uni.$u.sleep(2000).then(()=>{
									uni.navigateBack()
								})
							})
							.catch(err=>{
								uni.showToast({
									title:err.msg || err.message || '服务器异常',
									icon:'error',
									duration:2000
								})

							})
					}
				}
			})
		},
		formReset(){
			this.initData()
		},
		initData() {
			this.formData.machineNo = '';

			this.timer.machineNo = 0;
			this.disabled.machineNo = false;

			this.show.otherItem = false;

			this.formData.lotNo=''
			this.focus.lotNo=false
			this.timer.lotNo=0

			this.formData.lotProductCode=''
			this.focus.lotProductCode=false
			this.timer.lotProductCode=0

			this.formData.lotInfo = '';
			this.echo.lotNo = '';
			this.echo.productCode = '';
			this.timer.lotInfo = 0;
			
			this.show.lotInfo=false
			this.qrCode.lotNoFrom=0
			this.qrCode.lotNoLength=0
			this.qrCode.pnFrom=0
			this.qrCode.pnLength=0
			
			this.show.calendar=false
			this.formData.recordTimeDT=dayjs().format('YYYY-MM-DD')
			if(dayjs().hour()<7){
				this.formData.recordTimeDT=dayjs().subtract(1,'day').format('YYYY-MM-DD')
			} 
			this.formData.zlMachineNo=''
			this.show.zlPicker=false
			
			this.submitBtn.loading=false
			this.$nextTick(() => {
				this.focus.machineNo = true;
			});
			
			this.formData.okCount1=0
			this.formData.ngCount1=0
			this.formData.jxngCount1=0
			this.formData.okCount2=0
			this.formData.ngCount2=0
			this.formData.jxngCount2=0
			this.formData.okCount3=0
			this.formData.ngCount3=0
			this.formData.jxngCount3=0
			this.formData.okCount4=0
			this.formData.ngCount4=0
			this.formData.jxngCount4=0
			this.formData.ymcCheck=''
			this.echo.ymcCheckUserFullName=''
			this.formData.lotEndFlag=false
		}
	}
};
</script>

<style scoped lang="scss">
.echo {
	margin-left: 80px;
}
.preWhite{
	white-space: pre;
}
.ngEcho{
	padding: 10px 0;
}
</style>
